package com.lwj.charts.Time;

import com.lwj.charts.commonutils.SendMessageSercice;
import com.lwj.charts.commonutils.WebSocketServer;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;

import java.sql.SQLException;

@Slf4j
@Configuration
@EnableScheduling
public class SendMessageToWeb {
    @Autowired
    private SendMessageSercice sendMessageSercice;
    boolean t = false;

    @Scheduled(cron = "0/5 * * * * ?")
    public void sendTestMessage() {
        if (WebSocketServer.webSocketSet.size() > 0) {
            if (t) {
                t = false;
                try {
                    sendMessageSercice.sendDataToWeb();
                } catch (SQLException e) {
                    e.printStackTrace();
                }
            } else {
                t = true;
                try {
                    sendMessageSercice.sendDataToWebTime();
                } catch (SQLException e) {
                    e.printStackTrace();
                }
            }
        }

    }

}
